<!--
 * @Date: 2025-06-11 13:39:56
 * @LastEditors: Csir 2215995096@qq.com
 * @LastEditTime: 2025-06-11 17:33:42
 * @FilePath: \infomng-ui\src\views\workorder\newWorkorderschedulemain\productionSchedulingDetail.vue
-->
<template>
  <div class="production-schedule-table">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" label="序号" width="120" />
      <el-table-column prop="scheduleTime" label="日期" width="200" />
      <el-table-column prop="planQty" label="排产数量" />
    </el-table>

    <div class="pagination-container">
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalItems"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getInfoDateList } from "@/api/workorder/productionscheduling";
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      totalItems: 2,
    };
  },
  computed: {
    isLastPage() {
      return this.currentPage === Math.ceil(this.totalItems / this.pageSize);
    },
  },
  props: {
    lineId: {
      type: String,
      required: true,
    },
    scheduleTime: {
      type: String,
      required: true,
    },
    docNo: {
      type: String,
      required: true,
    },
    dialogVisibleDetail: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    // this.fetchData();
    console.log("挂载完成");
  },
  // 更新
  updated() {
    console.log("更新完成");
  },
  // 销毁前
  beforeDestroy() {
    console.log("销毁前");
  },
  watch: {
    dialogVisibleDetail: {
      immediate: true,
      handler(val) {
        if(val){
          this.currentPage = 1; 
          this.fetchData();
        }
      },
    },
  },
  methods: {
    async fetchData() {
      const params = {
        current: this.currentPage,
        size: this.pageSize,
        lineId: this.lineId,
        scheduleTime: this.scheduleTime,
        docNo: this.docNo,
      };
      const response = await getInfoDateList(params);

      if (response) {
        this.tableData = response.data.data.records;
        this.totalItems = response.data.data.total;
      }
    },
    handlePageChange(page) {
      this.currentPage = page;
      this.fetchData();
    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.currentPage = 1; // 重置为第一页
      this.fetchData();
    },
  },
};
</script>

<style scoped lang="less">
.pagination-container {
  margin-top: 20px;
  text-align: center;
  position: relative;
  right: 0;
  .pagination {
    position: absolute;
    right: 0;
  }
}
</style>
